<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function flat(arr) {
            let result = []
            for (const item of arr) {
                item instanceof Array ? result = result.concat(flat(item)) : result.push(item)
            }
            return result
        }
        const array = [1, 2, 3, [4, 5, [6, 7]]]
        console.log(flat(array))

        function flatByReduce(array) {
            return array.reduce((pre, curr) => {
                return pre.concat(curr instanceof Array ? flatByReduce(curr) : curr)
            }, [])
        }
        console.log('flatByReduce(array)',flatByReduce(array))

        
    </script>
</body>

</html>